
*===================================================================*
*   BIHAR EVALUATION OF SOCIAL FRANCHISING AND TELEMEDICINE (BEST)
*               Comparison Tables STANDARDIZED PATIENT
*====================================================================*


*====================================================================*
* Diarrhoea
* Fraction of Providers who Asked Key Diagnostic Questions, Diagnosis and Treatment
*====================================================================*

* Open data BASELINE
  use "$prodata1\standardized_patient_diarrhea_b", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata1\providers_interview_1st", keepus(treat sample1)
  keep if _merge==3
  drop _merge

* Sample selection I (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==192

* Sample selection II
/*NOTE: I will keep those with completed SP observations*/
  keep if sample2==1
  count

* Loop for Diarrhoea 

* Fraction of positive response (SP_ITEM)
  forvalues n=0/1 {
    mat table_base_d`n'=J(24,4,.)
    mat colnames table_base_d`n' = n mean sd .
    count if treat==`n'
    mat table_base_d`n'[24,1]=r(N)
    forvalues i = 1/11 {
      sum sp_item`i' if treat==`n'
      mat table_base_d`n'[`i',1]==r(N)*r(mean)
      mat table_base_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_base_d`n'[`i',3]==r(sd)
      }
    }

* Treatment, diagnosis and others
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  gen other = sp_item12
  gen miss=.
  local table "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"
  forvalues n=0/1 {
    local i 13
    foreach var of local table {
      sum `var' if treat==`n'
      mat table_base_d`n'[`i',1]==r(N)*r(mean)
      mat table_base_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_base_d`n'[`i',3]==r(sd)
      local i = `i'+1
      }
   mat table_base_d=nullmat(table_base_d), table_base_d`n'
   mat drop table_base_d`n'
    }


* Open data FOLLOW UP
  use "$prodata2\standardized_patient_diarrhea_b", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata2\providers_interview_2nd", keepus(treat TPC RHP WHP sample1)
  keep if _merge==3
  drop _merge

* Sample selection I (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 
  assert _N==194

* Sample selection II
/*NOTE: I will keep those with completed SP observations*/
  keep if sample2==1
  count

* Define group
  gen     group = 1 if treat==0
  replace group = 2 if treat==1 & WHP==0
  replace group = 3 if treat==1 & WHP==1
  tab group WHP

* Loop for Diarrhoea 

* Fraction of positive response (SP_ITEM)
  forvalues n=1/3 {
    mat table_foll_d`n'=J(24,4,.)
    mat colnames table_foll_d`n' = n mean sd .
    count if group==`n'
    mat table_foll_d`n'[24,1]=r(N)
      forvalues i = 1/11 {
        sum sp_item`i' if group==`n'
        mat table_foll_d`n'[`i',1]==r(N)*r(mean)
        mat table_foll_d`n'[`i',2]==round(r(mean)*100, .1)
        mat table_foll_d`n'[`i',3]==r(sd)
        }
  }

* Treatment, diagnosis and others
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  gen other = sp_item12
  gen miss=.
  local table "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"
  forvalues n=1/3 {
    local i 13
    foreach var of local table {
      sum `var' if group==`n'
      mat table_foll_d`n'[`i',1]==r(N)*r(mean)
      mat table_foll_d`n'[`i',2]==round(r(mean)*100, .1)
      mat table_foll_d`n'[`i',3]==r(sd)
      local i = `i'+1
      }
   mat table_foll_d=nullmat(table_foll_d), table_foll_d`n'
   mat drop table_foll_d`n'
    }


* Append tables baseline + follow up
  mat table_d = table_base_d, table_foll_d

* Appending one above the other for figures
/* First 24 observation belongs to non-implementation areas while the rest to implementation ones*/
  matselrc table_base_d base1, r(1/24) c(2)
  matselrc table_foll_d foll1, r(1/24) c(2)
  mat noimp = base1, foll1

  matselrc table_base_d base2, r(1/24) c(6)
  matselrc table_foll_d foll2, r(1/24) c(6)
  mat imp = base2, foll2
  mat figure_d = noimp\imp
  mat colnames figure_d = before after
  mat drop base1 base2 foll1 foll2 noimp imp


*====================================================================*
*                          TESTING MEANS 
* APPENDIX TABLE A5
* (1) Compare group 1 and group 3
* (2) Compare group 2 ang group 4
* (3) Compare group 4 and group 5
*====================================================================*

* Open data BASELINE and append
  use          "$prodata1\standardized_patient_diarrhea_b", clear
  append using "$prodata2\standardized_patient_diarrhea_b"

* Sample selection I (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 

* Sample selection II
/*NOTE: I will keep those with completed SP observations*/
  keep if sample2==1
  count
  assert _N==352

* Time spent with the SP 
  bys wave: sum visit_time if WHP!=1
  bys wave: sum visit_time
  reg visit_time wave, cluster(cluster)

* Number of medicines prescribed
  bys wave: sum nmedicines if WHP!=1
  reg nmedicines wave, cluster(cluster)


* Groups
  gen     group = 1 if treat==0 & wave==1
  replace group = 2 if treat==1 & wave==1
  replace group = 3 if treat==0 & wave==2
  replace group = 4 if treat==1 & wave==2 & WHP==0
  replace group = 5 if treat==1 & wave==2 & WHP==1

  gen     compare13 = .
  replace compare13 = 0 if group==1
  replace compare13 = 1 if group==3
  lab var compare13 "before-after comparison in Non-Implementation Areas"

  gen     compare24 = .
  replace compare24 = 0 if group==2
  replace compare24 = 1 if group==4
  lab var compare24 "before-after comparison in Implementation Areas"

  gen     compare45 = .
  replace compare45 = 0 if group==4
  replace compare45 = 1 if group==5
  lab var compare45 "Non-WHP vs WHP in Implementation Areas"

* Start loop by comparison group
  foreach c in 13 24 45 {

  * Define matrix to store results
    mat appendix_table_comp`c'= J(22,7,.)
    mat colnames appendix_table_comp`c' = mean0 mean1 pvalue Lci Uci g_pval empty

  * Loop over variables
    local r 1
    forvalues x = 1/11 {

    * Item
      reg sp_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 sp_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)

      local r = `r'+1
      }
    }

  * Treatment, diagnosis and others
    gen dx_type_if=dx_type if dx_any==1
    gen tx_type_if=tx_type if tx_any==1
    gen other = sp_item12
    gen miss=.
    local table "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  quietly foreach c in 13 24 45 {
  local r=13
    foreach var of local table {
      if "`var'"=="miss" local r = `r'+1       //jump miss variables//
      else {
      reg `var' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 `var' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)
      local r = `r'+1
      }
    }
  }

* Export Appendix Table with mean comparison
  mat appendix_table_comp = appendix_table_comp13, appendix_table_comp24, appendix_table_comp45
  mat drop appendix_table_comp13 appendix_table_comp24 appendix_table_comp45
  preserve
  drop _all
  svmat2 appendix_table_comp, rnames(variables)
  order variables, first
  outsheet using "$results\A5_diarrhea_sp.xls", replace
  restore





*====================================================================*
* PNEUMONIA
* Fraction of Providers who Asked Key Diagnostic Questions, Diagnosis and Treatment
*====================================================================*

* Open data BASELINE
  use "$prodata1\standardized_patient_pneumonia_b", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata1\providers_interview_1st", keepus(treat sample1)
  keep if _merge==3
  drop _merge

* Sample selection I (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 

* Sample selection II
  keep if sample3==1

* Loop for Pneumonia 

  * Fraction of positive response (SP_ITEM)
    forvalues n=0/1 {
      mat table_base_p`n'=J(24,4,.)
      mat colnames table_base_p`n' = n mean sd .
      count if treat==`n'
      mat table_base_p`n'[24,1]=r(N)
      forvalues i = 1/9 {
        sum sp_item`i' if treat==`n'
        mat table_base_p`n'[`i',1]==r(N)*r(mean)
        mat table_base_p`n'[`i',2]==round(r(mean)*100, .1)
        mat table_base_p`n'[`i',3]==r(sd)
        }
    }

  * Treatment, diagnosis and others
    gen dx_type_if=dx_type if dx_any==1
    gen tx_type_if=tx_type if tx_any==1
    gen other = sp_item10
    gen miss=.
    local table "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"
    forvalues n=0/1 {
      local i 13
      foreach var of local table {
        sum `var' if treat==`n'
        mat table_base_p`n'[`i',1]==r(N)*r(mean)
        mat table_base_p`n'[`i',2]==round(r(mean)*100, .1)
        mat table_base_p`n'[`i',3]==r(sd)
        local i = `i'+1
        }
     mat table_base_p=nullmat(table_base_p), table_base_p`n'
     mat drop table_base_p`n'
      }



* Open data FOLLOW UP
  use "$prodata2\standardized_patient_pneumonia_b", clear

* Get treatment variable
  merge 1:1 prov_id using "$prodata2\providers_interview_2nd", keepus(treat TPC RHP WHP sample1)
  keep if _merge==3
  drop _merge

* Sample selection I (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 

* Sample selection
  keep if sample3==1

* Define group
  gen     group = 1 if treat==0
  replace group = 2 if treat==1 & WHP==0
  replace group = 3 if treat==1 & WHP==1
  tab group WHP


* Loop for Pneumonia 

* Fraction of positive response (SP_ITEM)
  forvalues n=1/3 {
    mat table_foll_p`n'=J(24,4,.)
    mat colnames table_foll_p`n' = n mean sd .
    count if group==`n'
    mat table_foll_p`n'[24,1]=r(N)
    forvalues i = 1/9 {
      sum sp_item`i' if group==`n'
      mat table_foll_p`n'[`i',1]==r(N)*r(mean)
      mat table_foll_p`n'[`i',2]==round(r(mean)*100, .1)
      mat table_foll_p`n'[`i',3]==r(sd)
      }
  }

* Treatment, diagnosis and others
  gen dx_type_if=dx_type if dx_any==1
  gen tx_type_if=tx_type if tx_any==1
  gen other = sp_item10
  gen miss=.
  local table "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"
  forvalues n=1/3 {
    local i 13
    foreach var of local table {
      sum `var' if group==`n'
      mat table_foll_p`n'[`i',1]==r(N)*r(mean)
      mat table_foll_p`n'[`i',2]==round(r(mean)*100, .1)
      mat table_foll_p`n'[`i',3]==r(sd)
      local i = `i'+1
      }
   mat table_foll_p=nullmat(table_foll_p), table_foll_p`n'
   mat drop table_foll_p`n'
    }


* Append tables baseline + follow up
  mat table_p = table_base_p, table_foll_p

* Appending one above the other for figures
/* First 31 observation belongs to non-implementation areas while the rest to implementation ones*/
  matselrc table_base_p base1, r(1/24) c(2)
  matselrc table_foll_p foll1, r(1/24) c(2)
  mat noimp = base1, foll1

  matselrc table_base_p base2, r(1/24) c(6)
  matselrc table_foll_p foll2, r(1/24) c(6)
  mat imp = base2, foll2
  mat figure_p = noimp\imp
  mat colnames figure_p = before after
  mat drop base1 base2 foll1 foll2 noimp imp

* Export tables
  local table "d p"
  foreach t of local table {
    preserve
    drop _all
    svmat2 table_`t', rnames(variables)
    cap order variables, first
    foreach num in 2 3 6 7 10 11 14 15 18 19 {
      rename table_`t'`num' table_`t'`num'_old
      gen str8 table_`t'`num'=string(table_`t'`num'_old, "%9.2f")
      replace table_`t'`num'="" if table_`t'`num'== "."
      drop table_`t'`num'_old
      }

    order table_`t'1, after(variables)
    forvalues n=19(-1)2 {
      order table_`t'`n', after(table_`t'1)
    }
    outsheet using "$results\table_`t'_sp.xls", replace
    restore
    }



*====================================================================*
*                          TESTING MEANS 
* APPENDIX TABLE A6
* (1) Compare group 1 and group 3
* (2) Compare group 2 ang group 4
* (3) Compare group 4 and group 5
*====================================================================*

* Open data BASELINE and append
  use          "$prodata1\standardized_patient_pneumonia_b", clear
  append using "$prodata2\standardized_patient_pneumonia_b"

* Sample selection I (see do file 3_samples)
  sort wave prov_id
  merge 1:1 wave prov_id using "$prodata\sample_by_wave"
  keep if _merge==3
  drop _merge 

* Sample selection II
/*NOTE: I will keep those with completed SP observations*/
  keep if sample3==1
  assert _N==330

* Groups
  gen     group = 1 if treat==0 & wave==1
  replace group = 2 if treat==1 & wave==1
  replace group = 3 if treat==0 & wave==2
  replace group = 4 if treat==1 & wave==2 & WHP==0
  replace group = 5 if treat==1 & wave==2 & WHP==1

  gen     compare13 = .
  replace compare13 = 0 if group==1
  replace compare13 = 1 if group==3
  lab var compare13 "before-after comparison in Non-Implementation Areas"

  gen     compare24 = .
  replace compare24 = 0 if group==2
  replace compare24 = 1 if group==4
  lab var compare24 "before-after comparison in Implementation Areas"

  gen     compare45 = .
  replace compare45 = 0 if group==4
  replace compare45 = 1 if group==5
  lab var compare45 "Non-WHP vs WHP in Implementation Areas"

* Start loop by comparison group
  foreach c in 13 24 45 {

  * Define matrix to store results
    mat appendix_table_comp`c'= J(20,7,.)
    mat colnames appendix_table_comp`c' = mean0 mean1 pvalue Lci Uci g_pval empty

  * Loop over variables
    local r 1
    forvalues x = 1/9 {

    * Item
      reg sp_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 sp_item`x' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)

      local r = `r'+1
      }
    }

  * Treatment, diagnosis and others
    gen dx_type_if=dx_type if dx_any==1
    gen tx_type_if=tx_type if tx_any==1
    gen other = sp_item10
    gen miss=.
    local table "ask_child other miss dx_any dx_type dx_type_if miss tx_any tx_type tx_type_if"

  quietly foreach c in 13 24 45 {
  local r=11
    foreach var of local table {
      if "`var'"=="miss" local r = `r'+1       //jump miss variables//
      else {
      reg `var' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',1] = round(_b[_cons]*100, .1)
      mat appendix_table_comp`c'[`r',2] = round((_b[_cons] + _b[compare`c'])*100, .1)
      mat appendix_table_comp`c'[`r',3] = round((2 * ttail(e(df_r), abs(_b[compare`c']/_se[compare`c']))), .001)

      local ci_lower = (_b[compare`c'] - invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',4] = round(`ci_lower', .001)

      local ci_upper = (_b[compare`c'] + invttail(e(df_r),0.025)*_se[compare`c'])*100
      matrix appendix_table_comp`c'[`r',5] = round(`ci_upper', .001)

      clchi2 `var' compare`c', cluster(cluster)
      mat appendix_table_comp`c'[`r',6] = round(r(g_pval), .001)
      local r = `r'+1
      }
    }
  }

* Export Appendix Table with mean comparison
  mat appendix_table_comp = appendix_table_comp13, appendix_table_comp24, appendix_table_comp45
  mat drop appendix_table_comp13 appendix_table_comp24 appendix_table_comp45
  preserve
  drop _all
  svmat2 appendix_table_comp, rnames(variables)
  order variables, first
  outsheet using "$results\A6_pneumonia_sp.xls", replace
  restore




*====================================================================*
* Figure 3 - Diarrhoea AND PNEUMONIA
* Fraction of Providers who Asked Key Diagnostic Questions
*====================================================================*

  preserve
  drop _all

* Diarrhoea
  svmat2 figure_d, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=24
  replace area = "Implementation Area" if _n>24
  drop if (_n>=36 & _n<=48) | (_n>=12 & _n<=24)

  destring variables, gen(item) ignore("r")
  gen item2=""
  replace item2 = "Age of the child"          if item==1
  replace item2 = "Nature of stool"           if item==2
  replace item2 = "Frequency of stool"        if item==3
  replace item2 = "Quantity of stool"         if item==4
  replace item2 = "Questions about urination" if item==5
  replace item2 = "Child is active/playful?"  if item==6
  replace item2 = "Fever"                     if item==7
  replace item2 = "Abdominal pain"            if item==8
  replace item2 = "Vomiting"                  if item==9
  replace item2 = "What has the child eaten?" if item==10
  replace item2 = "Taking fluids?"            if item==11

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area"
  lab val area2 area2

  twoway (pcarrow item before item after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item before, pstyle(p1) ms(o)) ///
       (scatter item after, pstyle(p6) ms(S) msize(small)), by(area2, note("") legend(off) title("Diarrhoea")) ///
  ylab(1 "Age of the child" 2 "Nature of stool" 3 "Frequency of stool" 4 "Quantity of stool" 5 "Questions about urination" 6 "Child is active/playful?" 7 "Fever" 8 "Abdominal pain" 9 "Vomiting" 10 "What has the child eaten?" 11 "Taking fluids?", angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Questions and Examinations - SP", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small))  ///
  scheme(s2color) name(fig3_d, replace) fxsize(100)

* Pneumonia
  drop _all
  svmat2 figure_p, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=24
  replace area = "Implementation Area" if _n>24
  drop if (_n>=34 & _n<=48) | (_n>=10 & _n<=24)

  destring variables, gen(item) ignore("r")
  gen item2=""
  replace item2 = "Age of the child"       if item==1
  replace item2 = "Fever"                  if item==2
  replace item2 = "Breathing is rapid"     if item==3
  replace item2 = "Nostrils flaring, skin b/w ribs inwards" if item==4
  replace item2 = "Type of cough"          if item==5
  replace item2 = "Runny/blocked nose"     if item==6
  replace item2 = "Sounds while breathing" if item==7
  replace item2 = "Is the child weak?"     if item==8
  replace item2 = "Breastfeeding/immunization history" if item==9        

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area", replace
  lab val area2 area2

  twoway (pcarrow item before item after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item before, pstyle(p1) ms(o)) ///
       (scatter item after, pstyle(p6) ms(S) msize(small)), by(area2, note("") title("Pneumonia")) ///
  ylab(1 "Age of the child" 2 "Fever" 3 "Breathing is rapid" 4 "Nostrils flaring, skin b/w ribs inwards" 5 "Type of cough" 6 "Runny/blocked nose" 7 "Sounds while breathing" 8 "Is the child weak?" 9 "Breastfeeding/immunization history", angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Questions and Examinations - SP", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small))  ///
  scheme(s2color) name(fig3_p, replace) 

* Figure 3
  graph combine fig3_d fig3_p, col(1) ysize(16) xsize(10.0) graphregion(color(white)) xcommon name(Figure3, replace) title("{bf: Figure 3: Performance of Providers on Diagnostic Questions and Tests on Standardized Patient}" "{bf:Visits at Baseline and Follow-up, by WHP-Sky Implementation Area}", size(vsmall)) note("Notes: Implementation Area indicates study clusters where WHP-Sky program was implemented (50 out of 80 clusters).", size(tiny))
  graph export "$graphs\Figure3.emf", replace

  restore


*====================================================================*
* Figure 4 - Diarrhoea AND PNEUMONIA
* Other questions, Diagnosis and Treatment: Fraction of Providers
*====================================================================*

  preserve

* Diarrhoea
  drop _all
  svmat2 figure_d, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=24
  replace area = "Implementation Area" if _n>24
  keep if (_n>=13 & _n<=22) | (_n>=37 & _n<=46)
  drop if variables=="r15" | variables=="r19"

  destring variables, gen(item) ignore("r")
  recode item (13=1) (14=2) (16=3) (17=4) (18=5) (20=6) (21=7) (22=8), gen(item2)

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area", replace
  lab val area2 area2

  twoway (pcarrow item2 before item2 after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item2 before, pstyle(p1) ms(o)) ///
       (scatter item2 after, pstyle(p6) ms(S) msize(small)), by(area2, note("") legend(off) title("Diarrhoea")) ///
  ylab(1 "Father was asked to bring the child" 2 "Counseling on hygiene" 3 "Gave any diagnosis" 4 "Correct diagnosis" 5 "Correct diagnosis (if any)" 6 "Gave any treatment" 7 "Correct treatment" 8 "Correct Treatment (if any)" , angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Other Questions, Diagnosis and Treatment - SP", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small))  ///
  scheme(s2color) name(fig4_d, replace)

* Pneumonia
  drop _all
  svmat2 figure_p, rnames(variables) names(col)
  gen     area = "Non-Implementation Area" if _n<=24
  replace area = "Implementation Area" if _n>24
  keep if (_n>=13 & _n<=22) | (_n>=37 & _n<=46)
  drop if variables=="r15" | variables=="r19"

  destring variables, gen(item) ignore("r")
  recode item (13=1) (14=2) (16=3) (17=4) (18=5) (20=6) (21=7) (22=8), gen(item2)

  gen     area2 = 0 if area == "Non-Implementation Area"
  replace area2 = 1 if area == "Implementation Area"
  lab def area2 0 "Non-Implementation Area" 1 "Implementation Area", replace
  lab val area2 area2

  twoway (pcarrow item2 before item2 after, pstyle(p15) mlwidth(*0.5)) ///
       (scatter item2 before, pstyle(p1) ms(o)) ///
       (scatter item2 after, pstyle(p6) ms(S) msize(small)), by(area2, note("") title("Pneumonia")) ///
  ylab(1 "Father was asked to bring the child" 2 "Other children have similar symptoms" 3 "Gave any diagnosis" 4 "Correct diagnosis" 5 "Correct diagnosis (if any)" 6 "Gave any treatment" 7 "Correct treatment" 8 "Correct Treatment (if any)" , angle(horizontal) labgap(*3) labsize(small)) ///
  ytitle("Other Questions, Diagnosis and Treatment - SP", size(small)) legend(label(1 "") label(2 "Baseline") label(3 "Follow-up") col(3) size(small) order(2 3)) ///
  graphregion(color(white)) ylabel(, nogrid) yscale(reverse) xla(, labsize(small)) subtitle(, size(small)) xtitle("Percentage of Providers", size(small))  ///
  scheme(s2color) name(fig4_p, replace) 

* Figure 4
  graph combine fig4_d fig4_p, col(1) ysize(16) xsize(10.0) graphregion(color(white)) xcommon name(Figure4, replace) title("{bf:Figure 4: Performance of Providers on Diagnoses Made and Treatments Prescribed on}" "{bf:Standardized Patient Visits at Baseline and Follow-up, by WHP-Sky Implementation Area}", size(vsmall)) note(`"Notes: Implementation Area indicates study clusters where WHP-Sky program was implemented (50 out of 80 clusters). "Has expressed not to give"' `"antibiotics" represents percentage of providers who prescribed antibiotics on vignette interview, but claimed that the drug(s) that they prescribed was not"' `"an antibiotic. "Knowledge score" is the item response score, based on questions asked to interviewers. "Correct Treatment" is percentage of all providers"' `"in the group who prescribed the correct treatment while "Correct treatment (if any)" is the percentage among those giving any treatment."', size(tiny))
  graph export "$graphs\Figure4.emf", replace

  restore
